﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using Fayshine.VA.RIAService.Web;

namespace Fayshine.VA.Helpers
{
    public class ImageSourceConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            vaserver device = value as vaserver;
            camera camera = value as camera;

            BitmapImage image = new BitmapImage();

            if (device != null)
            {
                if (device.Status == 1)
                {
                    image = new BitmapImage(new Uri("/Fayshine.VA;component/Images/device_online.jpg", UriKind.Relative));
                }
                else
                {
                    image = new BitmapImage(new Uri("/Fayshine.VA;component/Images/device_offline.jpg", UriKind.Relative));
                }
            }
            else if (camera != null)
            {
                if (camera.IsOnle == true)
                {
                    image = new BitmapImage(new Uri("/Fayshine.VA;component/Images/camera_online.jpg", UriKind.Relative));
                }
                else
                {
                    image = new BitmapImage(new Uri("/Fayshine.VA;component/Images/camera_offline.jpg", UriKind.Relative));
                }
            }
            
            return image;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
